<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        //es6继承

        // class Person{
        //     constructor(name,age){
        //         console.log("父级===constructor")
        //         this.name = name;
        //         this.age = age;
        //     }

        //     say(){
        //         console.log(this.name)
        //     }
        // }    

        // // let p1 = new Person('zs',19);

        // class Student extends Person{
        //     constructor(name,age){
        //         console.log("=====",name,age);
        //         super(name,age) //super调用的是父级的constructor,把父级的this指向Student
        //     }
        //     learn(){
        //         console.log(this.name,'在学习')
        //     }
        // }

        // let s1 = new Student('lili',10);

        // // s1.learn()
        // s1.say()


        //ES5继承  借用构造函数+原型继承 = 组合式继承

        function Person(name,age){
            console.log(this);
            this.name = name;
            this.age = age;
        }    

        Person.prototype.say = function(){
            console.log("====",this.name)
        }

        // Person('name',10)  window

        // new Person('name',10)  person实例

        function Student(){ //call apply   bind
            Person.apply(this,arguments);  //借用构造函数  成员的属性和方法
        }

        Student.prototype = Object.create(Person.prototype); //原型继承  原型的属性和方法

        //重新Student的constructor
        Student.prototype.constructor = Student;

        Student.prototype.learn = function(){
            console.log(this.name,'学习')
        }

        let s1 = new Student('lili',19);

        // s1.learn();
        // console.log(s1.age)

        s1.say();

        let p1 = new Person('zs',10);

        console.log(p1.__proto__)

        
    </script>
</body>
</html>